package com.yanqu.road.server.cmd.beauty;

import com.yanqu.road.entity.config.beauty.BeautyModifySkillResult;
import com.yanqu.road.server.pb.BeautyPb;
import com.yanqu.road.pb.beauty.BeautyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/9/28 15:23
 */
@Cmd(code = GameProtocol.S_BEAUTY_SKILL_MODIFY_AUTO, desc = "技能改装自动化")
public class BeautySkillModifyAutoCmd extends AbstractCommand {
    private int beautyId;
    private int skillPos;
    private boolean isCustomize;
    private long goalVal;
    private String costLimit;
    private int markId;
    private boolean isBegin;
    private BeautyModifySkillResult result;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BeautyProto.BeautySkillModifyAutoReqMsg msg = BeautyProto.BeautySkillModifyAutoReqMsg.parseFrom(packet.getBytes());
        beautyId = msg.getBeautyId();
        skillPos = msg.getSkillPos();
        isCustomize = msg.getIsCustomize();
        goalVal = msg.getGoalVal();
        costLimit = msg.getCostLimit();
        markId = msg.getMarkId();
        isBegin = msg.getIsbegin();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        result = player.getModule(BeautyModule.class).beautySkillModifyAuto(beautyId, skillPos, isCustomize, goalVal, costLimit, isBegin);
    }

    @Override
    public void sendData(GamePlayer player) {
        BeautyProto.BeautySkillModifyAutoRespMsg.Builder respMsg = BeautyProto.BeautySkillModifyAutoRespMsg.newBuilder();
        respMsg.setMarkId(markId);
        respMsg.setRet(result.getRet());
        if(result.getBeautySkill() != null){
            respMsg.setIsReplace(result.isReplace());
            BeautyProto.BeautySkillTempMsg.Builder skillMsg = BeautyPb.parseBeautySkillTempMsg(result.getBeautySkill());
            if(null != skillMsg) {
                respMsg.setBeautySkill(skillMsg);
            }
            respMsg.setCurValue(result.getCurValue());
        }
        player.sendPacket(ClientProtocol.U_BEAUTY_SKILL_MODIFY_AUTO, respMsg);
    }
}
